home *** CD-ROM | disk | FTP | other *** search
-
- /*
- Name: postsplit.c
- Processor: Amiga 68000
- Compiler directive: lc -L xxx.c
- Creation Date: 27 Oct 92
- Version: 1.05
- Author: I Parker
-
- Description Splits pagestream colour postscript output into separate files
- analyses files and can turn into encapsulated format
-
- Known bugs:- At 'End Page' key words, two cr's are placed
-
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #define UNLOCK 0
- #define LOCK 1
-
- FILE *ifp, *ofp, *fopen();
- void Rout1(), Rout2(), Rout3(), Rout4(), Output(), Stop();
- char inline[300];
- char outline[300];
- char drv[46];
- int index,a,b;
-
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- if(argc != 3)
- {
- printf("\033[33mpostsplit by I Parker V1.05\n");
- /* \033[33m = prt blue */
- printf("Usage:- postsplit file.ps ([cyan|magenta|yellow|black|spotcolour]\n");
- printf("[anl|fnt|eps])\033[31m\n");
- /* \033[31m = reset */
- }
-
- if(argv[2][0] == 'a' && argv[2][1] == 'n' && argv[2][2] == 'l')
- {
- Rout1(argv);
- }
- if(argv[2][0] == 'f' && argv[2][1] == 'n' && argv[2][2] == 't')
- {
- Rout3(argv);
- }
- if(argv[2][0] == 'e' && argv[2][1] == 'p' && argv[2][2] == 's')
- {
- Rout4(argv);
- }
- if(argc == 3)
- {
- Rout2(argv);
- }
- } /* end of main */
-
- void Rout1(anl) /* routine to analyse the file */
- char *anl[];
- {
- char name[40];
- printf("Enter Destination Drive ie RAM:\n");
- scanf("%s",&drv);
- if((ifp = fopen(anl[1],"r"))==NULL)
- {
- fprintf(stderr, "Error : Cannot open input file %s\n", strupr(anl[1]));
- exit(-1);
- }
- strcpy(name,anl[1]);
- strcat(name,".anl");
- strcat(drv,name);
-
- if((ofp = fopen(drv, "wb"))==NULL)
- {
- fprintf(stderr, "Error: Unable to open output file %s\n",drv);
- exit(1);
- }
- printf("postscript analysis routine\n");
- while(fgets(inline,300,ifp)!=NULL) /* to end of file */
- {
- index = 0;
- a = 0;
- for (index=0; inline[index] != '\0'; index++)
- switch(inline[index])
- {
- case '%': { a=4; } break;
-
- case '!': { if(a==4) { a=30; Output('\n'); Output(inline[index]); } } break;
-
- case '(': { a=2; } break;
-
- case '"': { if(a==2) { a=10; Output('\n'); Output(inline[index]); } } break;
-
- default: if(a > 5) { Output(inline[index]); }
-
- } /* end of switch */
- } /* end of while - null */
-
- Stop();
- } /* end of rout1 */
-
- void Rout2(spl) /* routine to split the file */
- char *spl[];
- {
- char name[40]; /* this is so that the o/p file name can be generated with */
- /* a suffix attached */
- int index;
- int flag = UNLOCK;
- int countbig = 1; /* count beginings */
- int countend = 1; /* count endings */
- int preq = 0; /* page required */
- int pmax = 0; /* maximum page in file */
- {
- if(spl[2][0] == 'a' && spl[2][1] == 'n' && spl[2][2] == 'l')
- return;
- if(spl[2][0] == 'e' && spl[2][1] == 'p' && spl[2][2] == 's')
- return;
- if(spl[2][0] == 'f' && spl[2][1] == 'n' && spl[2][2] == 't')
- return;
-
- printf("Enter Destination Drive ie DF0:\n");
- scanf("%s",&drv);
-
- if((ifp = fopen(spl[1],"r"))==NULL) {
- fprintf(stderr, "Error : Cannot open input file %s\n", strupr(spl[1]));
- exit(-1);
- }
- strcpy(name,spl[1]); /* create o/p file name from i/p names */
- strcat(name,".");
- strcat(name,spl[2]);
- strcat(drv,name);
-
- if((ofp = fopen(drv, "wb"))==NULL) {
- fprintf(stderr, "Error : Unable to open output file %s\n",drv);
- exit(1);
- }
- printf("Enter page number required \n");
- scanf("%d",&preq);
- preq = preq+1;
- printf("Enter maximum page number in file \n");
- scanf("%d",&pmax);
- pmax = pmax+1;
- printf("Splitting postscript file generating %s fragment\n",name);
- while(fgets(inline,300,ifp)!=NULL)
- {
- index = 0;
- a = 0;
- b = 0;
- for (index=0; inline[index] != '\0'; index++)
- {
- if(countbig < 2)
- {
- Output(inline[index]);
- }
- if(preq == countbig)
- {
- Output(inline[index]);
- }
- if(preq == countend)
- {
- countbig=100;
- }
- if(pmax == countend)
- {
- Output(inline[index]);
- }
- switch(inline[index]) /* fine phrase % Begin P*/
- {
- case '%': { a=1; } break;
-
- case ' ': { if(a==1) a=2; if(a==7) a=8; } break;
-
- case 'B': { if(a==2) a=3;else a=0; } break;
-
- case 'e': { if(a==3) a=4;else a=0; } break;
-
- case 'g': { if(a==4) a=5;else a=0; } break;
-
- case 'i': { if(a==5) a=6;else a=0; } break;
-
- case 'n': { if(a==6) a=7;else a=0; } break;
-
- case 'P': { if(a==8) {flag = LOCK; a=9;countbig++;}else a=0;} break;
-
- default: break;
-
- } /* end of switch */
- switch(inline[index]) /* fine phrase % End P*/
- {
- case '%': { b=11;} break;
-
- case ' ': { if(b==11) b=12; if(b==15) b=16; } break;
-
- case 'E': { if(b==12) b=13;else b=0; } break;
-
- case 'n': { if(b==13) b=14;else b=0; } break;
-
- case 'd': { if(b==14) b=15;else b=0; } break;
-
- case 'P': { if(b==16) {b=17;}else b=0; } break;
-
- case 'a': { if(b==17) {b=18;}else b=0;}break;
-
- case 'g': { if(b==18) {b=19;}else b=0;}break;
-
- case 'e': { if(b==19) {countend++;}else b=0;}break;
-
- default: break;
-
- } /* end of else */
- } /* end of for */
- }
- }
- Stop();
- } /* end of rout2 */
-
- void Rout3(blc)
- char *blc[];
- {
- char name[40]; /* this is so that the o/p file name can be generated with */
- /* a suffix attached */
- int index;
- int countfnt = 0;
- printf("Enter Destination Drive ie DF0:\n");
- scanf("%s",&drv);
- {
- if((ifp = fopen(blc[1],"r"))==NULL) {
- fprintf(stderr, "Error : Cannot open input file %s\n", strupr(blc[1]));
- exit(-1);
- }
- strcpy(name,blc[1]); /* create o/p file name from i/p names */
- strcat(drv,name);
- strcat(drv,".FNT");
-
- if((ofp = fopen(drv, "wb"))==NULL) {
- fprintf(stderr, "Error : Unable to open output file %s\n",drv);
- exit(1);
- }
- printf("Extracting adobe font data (other fonts must be done manualy)\n");
- while(fgets(inline,300,ifp)!=NULL)
- {
- index = 0;
- a = 0;
- for (index=0; inline[index] != '\0'; index++)
- {
- if (a==2 && countfnt == 2)
- {
- a=0;
- Output('%');
- Output('!');
- }
- if( countfnt > 1)
- {
- Output(inline[index]);
- }
-
- switch(inline[index]) /* fine phrase % Begin P*/
- {
- case '%': { a=1; } break;
-
- case '!': { if(a==1) {a=2;countfnt++;}} break;
-
- default: {a=0;break;}
- } /* end of switch */
-
- } /* end of for */
- }
- }
- Stop();
- } /* end of rout3 */
-
- void Rout4(eps) /* Routine to convert to EPSF format */
- char *eps[];
- {
- char name[40];
- int flag = UNLOCK;
- printf("Enter Destination Drive ie DFO:\n");
- scanf("%s",&drv);
- if((ifp = fopen(eps[1],"r"))==NULL)
- {
- fprintf(stderr, "Error : Cannot open input file %s\n", strupr(eps[1]));
- exit(-1);
- }
- strcpy(name,eps[1]);
- strcat(drv,name);
- strcat(drv,".EPSF");
-
- if((ofp = fopen(drv, "wb"))==NULL)
- {
- fprintf(stderr, "Error: Unable to open output file %s\n",drv);
- exit(1);
- }
- printf("There must be no crop marks and only one page (b/w or col)\n");
- printf("Converting to Encapsulated format\n");
- while(fgets(inline,300,ifp)!=NULL) /* to end of file */
- {
- index = 0;
- a = 0;
- for (index=0; inline[index] != '\0'; index++)
- if (flag==LOCK)
- {
- Output(inline[index]);
- }
- if (flag != LOCK)
- {
- Output ('%');
- Output ('!');
- Output ('P');
- Output ('S');
- Output ('-');
- Output ('A');
- Output ('d');
- Output ('o');
- Output ('b');
- Output ('e');
- Output ('-');
- Output ('3');
- Output ('.');
- Output ('0');
- Output (' ');
- Output ('E');
- Output ('P');
- Output ('S');
- Output ('F');
- Output ('-');
- Output ('3');
- Output ('.');
- Output ('0');
- Output ('\n');
- flag=LOCK;
- }
- } /* end of while - null */
-
- Stop();
- } /* end of rout4 */
-
- void Output(ili)
- char ili;
- {
- putc(ili,ofp);
-
- }
-
- void Stop()
- {
- fclose(ifp);
- fclose(ofp);
- exit();
- }